import { createRouter, createWebHashHistory,createWebHistory } from 'vue-router'
import store from '../store/index'
console.log(store);

const routes = [
  
  // 登陆
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "Login" */ '@/views/Login.vue'),
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import(/* webpackChunkName: "Home" */ '@/views/Home.vue'),
    children:[{
      path: '/profile',
      name: 'profile',
      component: () => import(/* webpackChunkName: "Home" */ '@/views/profile.vue'),
    },{
      path: '/chart',
      name: 'chart',
      component: () => import(/* webpackChunkName: "Home" */ '@/views/chart.vue'),
    },{
      path: '/manage',
      name: 'manage',
      component: () => import(/* webpackChunkName: "Home" */ '@/views/manage.vue'),
    },{
      path: '/i18n',
      name: 'i18n',
      component: () => import(/* webpackChunkName: "Home" */ '@/views/i18n.vue'),
    },{
      path: '/role',
      name: 'role',
      component: () => import(/* webpackChunkName: "Home" */ '@/views/role.vue'),
    },{
      path: '/permission',
      name: 'permission',
      component: () => import(/* webpackChunkName: "Home" */ '@/views/permission.vue'),
    }]
  },
  //以下为测试页面
  {
    path: '/about', 
    name: 'About',
    component: () => import('@/views/About.vue')
  },
  {
    path: '/test',//vue3基本语法演示
    name: 'Test',
    component: () => import('@/views/Test.vue')
  },
   //根目录,到登录页面
   {
    path: '/',
    redirect: '/login'
  },
  //找不到页面到404,！！注意vue3里不能用*
  // {
  //  path: '/:catchAll(.*)',
  //  redirect: '/404'
  // }
]




const router = createRouter({
  history: createWebHashHistory(), // hash模式：createWebHashHistory，history模式：createWebHistory
  routes
})

const tabs=['/login','/home']

router.beforeEach((to,from,next)=>{
  console.log(to);
  if(tabs.indexOf(to.path)==-1){
    let obj={
      path:to.path,
      name:to.name,
      flag:true,
    }
    store.commit('addtabs', obj);
  }
  next()
})

export default router
